package com.lagou.module2.task1;
import java.util.Scanner;
/**
 * 游戏运行文件
 */
public class ChessTest{
    public static void main(String[] args) {
        //打印棋盘
        Scanner sc = new Scanner(System.in);
        ChessBoard cb = new ChessBoard();
        System.out.println("五子棋盘已绘制");
        cb.getBoard();
        //游戏规则介绍
        System.out.println("游戏规则为："+"\n"+"1.黑子先手"+"\n"+"2.先将自己的五枚棋子连成同一条线者胜(斜着也算哦)！");
        do {
            //黑棋落子
            System.out.println("请黑棋&选择落子的坐标(a b格式)：");
            String index1 = sc.nextLine();
            String[] index2 = index1.split(" ");
            int[] black = cb.getCoordinates(index2);
            if (cb.isRepeat(black)){continue;}
            else {cb.blackPlay(black);}
            if (cb.ifBlack(black)==true){
                System.out.println("黑棋胜");
                break;
            }

            //白棋落子
            System.out.println("请白棋#选择落子的坐标(a b格式)：");
            String index3 = sc.nextLine();
            String[] index4 = index3.split(" ");
            int[] white = cb.getCoordinates(index4);
            while(cb.isRepeat(white)){
                index3 = sc.nextLine();
                index4 = index3.split(" ");
                white = cb.getCoordinates(index4);
            }
            cb.whitePlay(white);
            //判断是否有人胜利
            if (cb.ifWhite(white)==true){
                System.out.println("白棋胜");
                break;
            }
        }
        while (true);
        //游戏结束
        System.out.println("游戏结束！");
    }
}
